package com.bootdo.wx.service.impl;

import com.bootdo.wx.dao.GoodsSpecDao;
import com.bootdo.wx.dao.GoodsTypeSpecDao;
import com.bootdo.wx.dao.GoodsTypeSpecValuesDao;
import com.bootdo.wx.domain.GoodsTypeSpecDO;
import com.bootdo.wx.service.GoodsTypeSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service
public class GoodsTypeSpecServiceImpl implements GoodsTypeSpecService {
	@Autowired
	private GoodsTypeSpecDao goodsTypeSpecDao;
	@Autowired
	private GoodsSpecDao goodsSpecDao;
	@Autowired
	private GoodsTypeSpecValuesDao goodsTypeSpecValuesDao;
	
	@Override
	public GoodsTypeSpecDO get(String id){
		return goodsTypeSpecDao.get(id);
	}
	
	@Override
	public List<GoodsTypeSpecDO> list(Map<String, Object> map){
		return goodsTypeSpecDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return goodsTypeSpecDao.count(map);
	}
	
	@Override
	public int save(GoodsTypeSpecDO goodsTypeSpec){
		return goodsTypeSpecDao.save(goodsTypeSpec);
	}
	
	@Override
	public int update(GoodsTypeSpecDO goodsTypeSpec){
		return goodsTypeSpecDao.update(goodsTypeSpec);
	}
	
	@Override
	public int remove(String id){
		return goodsTypeSpecDao.remove(id);
	}
	
	@Override
	public int batchRemove(String[] ids){
		return goodsTypeSpecDao.batchRemove(ids);
	}

	@Override
	public List<GoodsTypeSpecDO> queryListAndValueByTypeId(String typeId) {
		List<GoodsTypeSpecDO> list = goodsTypeSpecDao.queryByTypeId(typeId);

		if (list!=null && list.size()>0){
			for (GoodsTypeSpecDO typeSpecDO:list){
				typeSpecDO.setSpec(goodsSpecDao.get(typeSpecDO.getSpecId()));
				typeSpecDO.setSpecValList(goodsTypeSpecValuesDao.queryByTypeSpecId(typeSpecDO.getId()));
			}
		}
		return list;
	}
	
}
